﻿<%@ Page Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ServicePackage.aspx.cs" Inherits="Hosting.ServicePackage" %>

<%@ Register Assembly="obout_SuperForm" Namespace="Obout.SuperForm" TagPrefix="obout" %>

<%@ Register Assembly="obout_Grid_NET" Namespace="Obout.Grid" TagPrefix="obout" %>

<asp:Content ContentPlaceHolderID="HeadContent" runat="server">
<script type="text/javascript" src="js/GridMessageValid.js"></script>
<script type="text/javascript" src="js/ServicePackage.js"></script>
<script type="text/javascript" src="js/ServiceCategories.js"></script>
<script type="text/javascript" src="js/CategoryDetail.js"></script>
<style type="text/css">
        
	#<%= UpdateProgress1.ClientID %>
    {
        position: absolute;
        z-index: 50; 
        top: 0px; 
        bottom: 0px; 
        left: -5px; 
        right: 5px; 
        width: auto; 
        height: auto;
        background-color: #EEEEEE;
        text-align: center;
        filter: alpha(opacity=60);
        -moz-opacity: 0.6;
        opacity: 0.6;
    }
        
    .loading-image
    {
        position: absolute;
        font-family: Verdana;
	    font-size: 10px;
	    color:#0C416F;
	    height: 10px;
	    top: 50%;	
	    bottom: 0px;
	    margin-top: -5px;	
	    left: 0px;
	    right: 0px;
	    margin-left: auto;
	    margin-right: auto;
	    text-align: center;
	    width: 100%;
    }
</style>

<script type="text/javascript">
    function dgCDetail_BeforeClientEdit(sender, record) {
        document.getElementById("<%=oldCId.ClientID %>").value = record.CId;
        document.getElementById("<%=oldCTId.ClientID %>").value = record.CTId;
        return true;
    }

    function filterGrid(ddl) {

        gHosting.addFilterCriteria('SPType', OboutGridFilterCriteria.EqualTo, ddl.value);
        gHosting.executeFilter();
    }

    function gHosting_BeforeClientDelete() {
        if (confirm("Are you sure to delete this Package\n Every children in this Package will delete too.") == false) {
            return false;
        }
        return true;
    }

    function dgCate_BeforeClientDelete() {
        if (confirm("Are you sure to delete this Category\n Every children in this Category will delete too.") == false) {
            return false;
        }
        return true;
    }

    function dgCDetail_ClientBeforeDelete() {
        if (confirm("Are you sure to delete this Detail!") == false) {
            return false;
        }
        return true;
    }

    function gHosting_Validation(sender, record) {
        var isValid = ServicePackageValid(record.SPName, record.SPCurrency, record.SPType);
        if (isValid == 1) {
            return 1;
        }
        else if (isValid == 10) {
            getMessageAttention("name is null or empty");
        }
        else if (isValid == 11) {
            getMessageAttention("name is greater than 50 characters");
        }
        else if (isValid == 20) {
            getMessageAttention("currency is null or empty");
        }
        else if (isValid == 21) {
            getMessageAttention("currency is greater than 50 characters");
        }
        else if (isValid == 30) {
            getMessageAttention("type is null or empty");
        }
        else if (isValid == 31) {
            getMessageAttention("type is greater than 50 characters");
        }
        else if (isValid == 40) {
            getMessageAttention("description is greater than 2000 characters");
        }
        setInterval(function () { hidediv('divGridValidation'); }, 6000);
        return false;
    }

    function dgCate_Validation(sender, record) {
        var isValid = CategoryValid(record.CName, record.CDescription, record.CFee);
        if (isValid == 1) {
            return true;
        }
        else if (isValid == 10) {
            getMessageAttention("Name is null or empty");
        }
        else if (isValid == 11) {
            getMessageAttention("Name is greater than 50 characters");
        }
        else if (isValid == 20) {
            getMessageAttention("Fee is not valid");
        }
        else if (isValid == 40) {
            getMessageAttention("description is greater than 2000 characters");
        }
        setInterval(function () { hidediv('divGridValidation'); }, 6000);
        return false;
    } function dgCDetail_Validation(sender, record) {
        var isValid = CategoryDetailValid(record.CDContent);
        if (isValid == 1) {
            return true;
        }
        else if (isValid == 6) {
            getMessageAttention("Content is greater than 2000 characters");
        }
        setInterval(function () { hidediv('divGridValidation'); }, 6000);
        return false;
    }

</script>

</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
<a href="#" id="anchorGridNotification"></a>
<div class="notification attention png_bg" id="divGridValidation" style="display:none;">
	<div id="divGridNotification" runat="server">
        <label id="GridNotificationLabel">Update status of control.</label>
	</div>
</div>
<asp:UpdatePanel ID="udp1" runat="server">
<ContentTemplate>

    <select id="sHostingDomain" runat="server" datasourceid="dsColors" datatextfield="SPType" datavaluefield="SPType">
    </select>

   <div style="position: relative; z-index: 0;">

   <%--Get old value of Category detail --%>
    <input type="hidden" runat="server" id="oldCId" />
    <input type="hidden" runat="server" id="oldCTId" />

    <obout:Grid ID="gHosting" runat="server" AllowRecordSelection="false" DataSourceID="ldsPackageAll" Serialize="false"
    AutoGenerateColumns="false" FilterType="ProgrammaticOnly" AllowFiltering="true" CallbackMode="false"
    OnInsertCommand="gHosting_InsertCommand"
    OnUpdateCommand="gHosting_UpdateCommand"
    OnDeleteCommand="gHosting_DeleteCommand" PageSizeOptions="5,10,20,50" AllowManualPaging="True">

        <ScrollingSettings ScrollWidth="5000px" />
        <ClientSideEvents ExposeSender="true" OnBeforeClientDelete="gHosting_BeforeClientDelete" OnBeforeClientInsert="gHosting_Validation" OnBeforeClientUpdate="gHosting_Validation" />

        <Columns>
            <obout:Column DataField="SPId" ReadOnly="true" Visible="false" HeaderText="ID">
                <TemplateSettings RowEditTemplateControlId="txtHSPId" />
            </obout:Column>
            <obout:Column DataField="SPName" HeaderText="Name" Width="250px">
                <TemplateSettings RowEditTemplateControlId="txtHName" />
            </obout:Column>
            <obout:Column DataField="SPCurrency" HeaderText="Currency" Width="150px">
                <TemplateSettings RowEditTemplateControlId="sHCurrency" />
            </obout:Column>
            <obout:Column DataField="SPType" HeaderText="Type" Width="150px">
                <TemplateSettings RowEditTemplateControlId="sHType" />
            </obout:Column>
            <obout:Column DataField="SPActive" HeaderText="Active">
                <TemplateSettings RowEditTemplateControlId="cbHActive" RowEditTemplateControlPropertyName="checked" />
            </obout:Column>
            <obout:Column DataField="SPDescription" HeaderText="Description" Visible="false">
                <TemplateSettings RowEditTemplateControlId="txtHDescription" />
            </obout:Column>
            <obout:Column AllowEdit="true" AllowDelete="true" AllowSorting="false" />
        </Columns>

        <TemplateSettings RowEditTemplateId="tlpEditHosting" />

        <Templates>
            <obout:GridTemplate ID="tlpEditHosting" runat="server">
                <Template>
                    <input type="hidden" id="txtHSPId" runat="server" />
                    <obout:SuperForm runat="server" ID="sfHosting" DefaultMode="Insert" DataKeyNames="SPId" DataSourceID="ldsHosting"
                    AutoGenerateRows="false" Width="99%"
                    AutoGenerateInsertButton="false"
                    AutoGenerateEditButton="false"
                    AutoGenerateDeleteButton="false">
                        <Fields>
                            <obout:TemplateField>
                            <HeaderTemplate>
                                <p style="height:25px;">
                                    <label for="txtHName">Name: </label>
                                </p>
                                <p style="height:25px;">
                                    <label for="sHCurrency">Currency: </label>
                                </p>
                                <p style="height:25px;">
                                    <label for="sHType">Type: </label>
                                </p>
                                <p style="height:25px;">
                                    <label for="cbHActive">Active: </label>
                                </p>
                                <p style="height:25px;">
                                    <label for="txtHDescription">Description:</label>
                                </p>
                            </HeaderTemplate>
                                <ItemTemplate>
                                    <p>
                                        <input type="text" class="medium-input" id="txtHName" runat="server" />
                                    </p>
                                    <p>
                                        <select class="medium-input" id="sHCurrency" runat="server">
                                            <option value="VND">VND</option>
                                            <option value="USD">USD</option>
                                        </select>
                                    </p>
                                    <p>
                                        <select class="medium-input" id="sHType" runat="server">
                                            <option value="hosting">Hosting</option>
                                            <option value="domain">Domain</option>
                                        </select>
                                    </p>
                                    <p>
                                        <input type="checkBox" id="cbHActive" runat="server" />
                                    </p>
                                    <p>
                                        <textarea class="medium-input" id="txtHDescription" runat="server" rows="20" cols="1"></textarea>
                                    </p>
                                </ItemTemplate>
                            </obout:TemplateField>

                        </Fields>

                    </obout:SuperForm>
                </Template>
            </obout:GridTemplate>
        </Templates>

        <MasterDetailSettings LoadingMode="OnCallback" ShowEmptyDetails="true" />

        <DetailGrids>
            <obout:DetailGrid id="dgCate" runat="server" AutoGenerateColumns="false" DataSourceID="ldsHostingCate" AllowColumnResizing="false"
                 AllowRecordSelection="false" Serialize="false" AllowFiltering="true"  CallbackMode="false"
                 OnInsertCommand="dgCate_InsertCommand"
                 OnUpdateCommand="dgCate_UpdateCommand"
                 OnDeleteCommand="dgCate_DeleteCommand"
                 PageSizeOptions="5,10,20,50" AllowManualPaging="True" AllowMultiRecordSelection="False" ForeignKeys="SPId">

            <ScrollingSettings ScrollWidth="5000px" />
            <ClientSideEvents ExposeSender="true" OnBeforeClientDelete="dgCate_BeforeClientDelete" OnBeforeClientInsert="dgCate_Validation" OnBeforeClientUpdate="dgCate_Validation" />

            <Columns>
                <obout:Column DataField="CId" HeaderText="Category Id" ReadOnly="true" runat="server" Visible="false">
                    <TemplateSettings RowEditTemplateControlId="txtHCId" />
                </obout:Column>
                <obout:Column DataField="SPId" HeaderText="Package Id" runat="server" Visible="false">
                    <TemplateSettings RowEditTemplateControlId="sHCPackage" />
                </obout:Column>
                <obout:Column DataField="CName" HeaderText="Name"  runat="server">
                    <TemplateSettings RowEditTemplateControlId="txtHCName" />
                </obout:Column>
                <obout:Column DataField="CFee" HeaderText="Fee"  runat="server">
                    <TemplateSettings RowEditTemplateControlId="txtHCFee" />
                </obout:Column>
                <obout:Column DataField="CActive" HeaderText="Active" runat="server">
                    <TemplateSettings RowEditTemplateControlId="cbHCActive" RowEditTemplateControlPropertyName="checked" />
                </obout:Column>
                <obout:Column DataField="CDescription" HeaderText="Description" runat="server">
                    <TemplateSettings RowEditTemplateControlId="txtHCDescription" />
                </obout:Column>
                <obout:Column AllowEdit="true" AllowDelete="true" AllowSorting="false" />
            </Columns>

            <TemplateSettings RowEditTemplateId="tlpEditHCate" />

            <Templates>
                <obout:GridTemplate ID="tlpEditHCate">
                    <Template>
                        <input type="hidden" id="txtHCId" runat="server" />

                            <fieldset style="padding-left: 150px;" class="myfield">
                                <p>
                                    <label for="sHCPackage">Package: </label>
                                    <select class="medium-input" id="sHCPackage" datasourceid="ldsPackageAll" datatextfield="SPName"
                                        datavaluefield="SPId" runat="server">
                                    </select>
                                </p>
                                <p>
                                    <label for="txtHCName">Name: </label>
                                    <input type="text" class="medium-input" id="txtHCName" runat="server" />
                                </p>
                                <p>
                                    <label for="txtHCFee">Fee: </label>
                                    <input type="text" class="medium-input" value="0" id="txtHCFee" runat="server" />
                                </p>
                                <p>
                                    <label for="cbHCActive">Active: </label>
                                    <input type="checkBox" id="cbHCActive" runat="server" />
                                </p>
                                <p>
                                    <label for="txtHCDescription">Description:</label>
                                    <textarea class="medium-input" id="txtHCDescription" runat="server" rows="10" cols="1"></textarea>
                                </p>
                            </fieldset>

                    </Template>
                </obout:GridTemplate>
            </Templates>
            
            <MasterDetailSettings LoadingMode="OnCallback" ShowEmptyDetails="true" />

            <DetailGrids>
                <obout:DetailGrid ID="dgCDetail" AutoGenerateColumns="false" DataSourceID="ldsHCDetail" ForeignKeys="CId" Serialize="false"
                    AllowFiltering="true" PageSizeOptions="5,10,20,50" CallbackMode="false"
                    OnInsertCommand="dgCDetail_InsertCommand"
                    OnUpdateCommand="dgCDetail_UpdateCommand"
                    OnDeleteCommand="dgCDetail_DeleteCommand">

                 <ScrollingSettings ScrollWidth="5000px" />
                 <ClientSideEvents ExposeSender="true" OnBeforeClientDelete="dgCDetail_ClientBeforeDelete" OnBeforeClientEdit="dgCDetail_BeforeClientEdit"
                    OnBeforeClientInsert="dgCDetail_Validation" OnBeforeClientUpdate="dgCDetail_Validation" />
                 
                    <Columns>
                        <obout:Column DataField="CId" HeaderText="Category ID" Visible="false">
                            <TemplateSettings RowEditTemplateControlId="sCId" />
                        </obout:Column>
                        <obout:Column DataField="CTId" HeaderText="Category Title ID" Visible="false">
                            <TemplateSettings RowEditTemplateControlId="sCTId" />
                        </obout:Column>
                        <obout:Column DataField="CName" HeaderText="Category"></obout:Column>
                        <obout:Column DataField="CTName" HeaderText="Title"></obout:Column>
                        <obout:Column DataField="CDActive" HeaderText="Active">
                            <TemplateSettings RowEditTemplateControlId="CDActive" RowEditTemplateControlPropertyName="checked" />
                        </obout:Column>
                        <obout:Column DataField="CDContent" HeaderText="Content">
                            <TemplateSettings RowEditTemplateControlId="txtCDContent" />
                        </obout:Column>
                        <obout:Column AllowEdit="true" AllowDelete="true" AllowSorting="false" />
                    </Columns>
                    
                    <TemplateSettings RowEditTemplateId="tlpEditHCateDetail" />
                    
                    <Templates>
                        <obout:GridTemplate ID="tlpEditHCateDetail">
                            <Template>

                                <fieldset style="padding-left: 150px;" class="myfield">
                                    <p>
                                        <label>Category: </label>

                                        <select class="medium-input" runat="server" id="sCId" datasourceid="ldsCateAll" datatextfield="CName" datavaluefield="CId">
                                        </select>
                                    </p>
                                    <p>
                                        <label>Title: </label>

                                        <select class="medium-input" runat="server" id="sCTId" datasourceid="ldsCateTitleAll" datatextfield="CTName" datavaluefield="CTId">
                                        </select>
                                    </p>
                                    <p>
                                        <label>Active:</label>
                                        <input type="checkbox" runat="server" id="CDActive" />
                                    </p>
                                    <p>
                                        <label>Content: </label>
                                        <textarea class="medium-input" id="txtCDContent" runat="server"></textarea>
                                    </p>
                                </fieldset>

                            </Template>
                        </obout:GridTemplate>
                    </Templates>

                </obout:DetailGrid>
            </DetailGrids>
            
            </obout:DetailGrid>

        </DetailGrids>

    </obout:Grid>

    <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="udp1">
        <ProgressTemplate>
			<div class="loading-image">
				<img src="../img/loaderWhite.gif" alt="Not image">
			</div>
        </ProgressTemplate>
    </asp:UpdateProgress>
    </div>
</ContentTemplate>
</asp:UpdatePanel>

    <asp:LinqDataSource ID="dsColors" runat="server" 
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext" 
    OrderBy="SPType" 
    Select="new (Key.SPType)"
    TableName="TBL_ServicePackages"
    GroupBy="new(SPType)">
</asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsPackageAll"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_ServicePackages"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true"></asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsPackage"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_ServicePackages"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true" Where="SPType=@SPType">
        <WhereParameters>
            <asp:Parameter Name="SPType" DefaultValue="domain" DbType="String" />
        </WhereParameters>
    </asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsCateAll"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_Categories" />

    <asp:LinqDataSource runat="server" ID="ldsCateTitleAll"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_CategoryTitles" />

    <asp:LinqDataSource runat="server" ID="ldsHosting"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_ServicePackages"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true" Where="SPId = @SPId">
        <WhereParameters>
            <asp:Parameter Name="SPId" DefaultValue="0" DbType="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsHostingCate"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_Categories"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true" Where="SPId = @SPId">
        <WhereParameters>
            <asp:Parameter Name="SPId" DefaultValue="0" DbType="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsEditHostingCate"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_Categories"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true" Where="CId = @CId">
        <WhereParameters>
            <asp:Parameter Name="CId" DefaultValue="0" DbType="Int32" />
        </WhereParameters>
    </asp:LinqDataSource>

    <asp:LinqDataSource runat="server" ID="ldsHCDetail"
    ContextTypeName="Hosting.Class.HostingDomainWebsiteDataContext"
    TableName="TBL_Categories"
    OnSelecting="ldsHCDetail_Selecting"
    EnableInsert="true"
    EnableUpdate="true"
    EnableDelete="true" Where="CId = @CId">
        <WhereParameters>
            <asp:Parameter Name="CId" DbType="Int32" DefaultValue="0" />
        </WhereParameters>
    </asp:LinqDataSource>

</asp:Content>
